#ifndef _GAMEFUNCTIONS_H_
#define _GAMEFUNCTIONS_H_

#include "GameNodeFun.h"
#include "LoadActorsFun.h"
#include "StateMachineFun.h"

#define FN_GAMEPLAY	0
#define TIMER_GAMEPLAY	0
#define FN_PLAYERFUNC	1
#define FN_TITLESCREEN	2
#define FN_ENEMYFUNC	3
#define FN_UPDATEOBJMAP	4
#define FN_UPDATEDELTATIME	5
#define FN_AICONTROLLER	6
#define FN_MOUSECONTROLLER	7



struct Vector2 {
	public:
	float x;
	float y;
	
	inline bool operator== (const int i) {
	  if (x!=i)
	    return false;
	  if (y!=i)
	    return false;
	  return true;
	}
	
	inline bool operator== (const Vector2 vect2) {
	  if (x!=vect2.x)
	    return false;
	  if (y!=vect2.y)
	    return false;
	  return true;
	}
	
	inline bool operator!= (const Vector2 vect2) {
	  if (x!=vect2.x)
	    return true;
	  if (y!=vect2.y)
	    return true;
	  return false;
	}
	
	inline bool operator!= (const int i) {
	  if (x!=i)
	    return true;
	  if (y!=i)
	    return true;
	  return false;
	}
	
	inline Vector2 operator+ (const Vector2 vect2) {
	  Vector2 newVect;
	  newVect.x = vect2.x + x;
	  newVect.y = vect2.y + y;
	  return newVect;
	}
	
	inline void operator+= (const Vector2 vect2) {
	  x += vect2.x;
	  y += vect2.y;
	}
	
	inline Vector2 operator* (const int i) {
	  Vector2 newVect;
	  newVect.x = x*i;
	  newVect.y = y*i;
	  return newVect;
	}
	
	static Vector2 GetUpVector() {
	  Vector2 upVect = {0, -1};
	  return upVect;
	}
	
	static Vector2 GetDownVector() {
	  Vector2 downVect = {0, 1};
	  return downVect;
	}
	
	static Vector2 GetLeftVector() {
	  Vector2 leftVect = {-1, 0};
	  return leftVect;
	}
	
	static Vector2 GetRightVector() {
	  Vector2 rightVect = {1, 0};
	  return rightVect;
	}
	
	static Vector2 GetZeroVector() {
	  Vector2 zeroVect = {0, 0};
	  return zeroVect;
	}
};

class MapData {
	public:
	Vector2 size;
	int** data;
	
	void MapData::Resize(const Vector2 newSize)
	{
	  data = (int**)realloc(data, sizeof(int)*newSize.x);
	  data = new int*[newSize.x];
	  for (int x = 0; x < newSize.x; x++)
	    data[x] = new int[newSize.y];
	  size = newSize;
	}
	
	void MapData::SetBinaryMap(const int bm[20][15])
	{
	  Vector2 vec = {20, 15};
	  Resize(vec);
	
	  int x, y;
	  for (x = 0; x < 20; x++)
	    for (y = 0; y < 15; y++)
	      data[x][y] = bm[x][y];
	}
};

extern MapData binaryMap;
extern MapData objMap;
extern float deltaTime;
extern float prevTime;

#define LD_OBJDATA 0
#define LD_DELTADATA 1

#include "MyFunctions.h"
extern void Gameplay(Map* This);
extern void PlayerFunc(Sprite* This);
extern void TitleScreen(Map* This);
extern void EnemyFunc(Sprite* This);
extern void UpdateObjMap(Sprite* This);
extern void UpdateDeltaTime(Game* This);
extern void AIController(Sprite* This);
extern void MouseController(FunCursor* This);

#endif
